from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus

from modules.case_qc.models.case_qc_model import CaseQc
from modules.case_qc.schemas.case_qc_schema import CaseQcCreate, CaseQcUpdate


class CaseQcRepository(CRUDPlus[CaseQc]):

    async def get_by_id(self, db: AsyncSession, pk: int):
        return await self.select_model_by_column(db, id=pk)

    async def create(self, db: AsyncSession, data: CaseQcCreate) -> CaseQc:
        return await self.create_model(db, data)

    async def update(self, db: AsyncSession, pk: int, data: CaseQcUpdate) -> Optional[CaseQc]:
        await self.update_model(db, pk, data)
        return await self.select_model(db, pk)

    async def delete(self, db: AsyncSession, pk: int) -> bool:
        return await self.delete_model(db, pk)


case_qc_dao = CaseQcRepository(CaseQc)